package org.springframework.zp.batis.config;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.zp.batis.util.MyScan;

import javax.sql.DataSource;

@Configuration
@ComponentScan("org.springframework.zp.batis")
// @MapperScan("org.springframework.zp.batis.dao")
//@ImportResource("classpath:spring-batis.xml")
// @Import(MyImportBeanDefinitionRegistart.class)
@MyScan(value = "org.springframework.zp.batis.dao")
public class BatisConfig {

	@Bean
	public DataSource dataSource(){
		DriverManagerDataSource driverManagerDataSource
				= new DriverManagerDataSource();
		driverManagerDataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
		driverManagerDataSource.setPassword("root");
		driverManagerDataSource.setUsername("root");
		driverManagerDataSource.setUrl("jdbc:mysql://localhost:3306/shadow?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC");
		return driverManagerDataSource;
	}
//
	@Bean
	public SqlSessionFactory sqlSessionFactory() throws Exception {
		SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
		factoryBean.setDataSource(dataSource());
		return factoryBean.getObject();
	}


//	@Bean
//	public TMapper tMapper(){
//		TMapper mapper = (TMapper) MySqlSession.getMapper(TMapper.class);
//		return mapper;
//	}
}
